package day16;

import java.util.Scanner;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2023/03/23  9:08
 */
public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String p = "34567891JQKA2";
        String[] poker = str.split("-");
        String[] p1 = poker[0].split(" ");
        String[] p2 = poker[1].split(" ");
        if(poker[0].equals("joker JOKER") || poker[1].equals("joker JOKER")){
            System.out.println("joker JOKER");
        } else if (p1.length == p2.length) {
            if(p.indexOf(p1[0].substring(0,1)) > p.indexOf(p2[0].substring(0,1))){
                System.out.println(poker[0]);
            }else {
                System.out.println(poker[1]);
            }
        } else if (p1.length == 4) {
            System.out.println(poker[0]);
        }else if(p2.length == 4){
            System.out.println(poker[1]);
        }else {
            System.out.println("ERROR");
        }
    }
}
